using UnityEngine;
using System.Collections;
using System.Threading;

public class LogScript : MonoBehaviour {
	public float LogTime = 5.0F;//Interval Log Time

	public string saveArea = "debugLog.txt";//Choose where to save

	public static ArrayList CurrentInfo = new ArrayList();
	

	
	
	Thread AltThread;
	// Use this for initialization
	void Start () {
	
		StartCoroutine(LogCounter());
		

	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	
	IEnumerator LogCounter ()
	{
		while(true)
		{
			AltThread = new Thread(Logger);
			
			yield return new WaitForSeconds(LogTime);
			
			
			AltThread.Start();
			//CurrentInfo.Clear();
		}
		
	}
	
	void Logger ()
	{
		lock(this)
		{
		
			string clear = " ";
			System.IO.File.WriteAllText(saveArea,clear);
			Debug.Log(CurrentInfo.Capacity.ToString());
			
		for(int i = 1;i<=CurrentInfo.Capacity;i++)
			{
				
				string current = CurrentInfo[i].ToString();
				System.IO.File.AppendAllText(saveArea,current);
				System.IO.File.AppendAllText(saveArea,"############*********###########");
				CurrentInfo.RemoveAt(i);
				i=1;
				
			}
			
			Debug.Log(CurrentInfo.Capacity.ToString());
			
		return;
		}
		
	}
	
	
	
	
	
	
	void OnApplicationQuit()
	{
		if(AltThread.IsAlive)
		{
		AltThread.Join();
		}
	}
	
	
}
